
package m2team.com.zuatet;

import java.util.ArrayList;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomListAdapter extends BaseAdapter {
    Context context;
    ArrayList<Item> lstItem;

    public CustomListAdapter(Context c, ArrayList<Item> lstItem) {
        context = c;
        this.lstItem = lstItem;
    }

    @Override
    public int getCount() {
        return lstItem.size();
    }

    @Override
    public Item getItem(int position) {
        return lstItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder holder = null;
        if (view == null) {// if current item is not showing --> must re-init it
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.include_item_1, parent, false);
            holder = new ViewHolder();
            holder.LabelView = (TextView) view.findViewById(R.id.item_label_id);
            holder.ImgView = (ImageView) view.findViewById(R.id.bg_item_id);
        }
        if (holder == null) {
            holder = (ViewHolder) view.getTag();
        }
        // get String in the position
        holder.LabelView.setText(lstItem.get(position).getLabel());
        holder.ImgView.setBackgroundResource(lstItem.get(position).getImgId());
        Common.setFont(context, holder.LabelView, Common.RobotoCondensed_Light);
        view.setTag(holder);
        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
    				Intent intent = new Intent(context, ContentActivity.class);
    				 context.startActivity(intent);
            }
        });
        return view;
    }

    private static class ViewHolder {
        private TextView LabelView;
        private ImageView ImgView;
    }
}
